// 挂载有问题，暂时没有使用
import Vue from 'vue'
import router from '../router'
import store from '../store'
import Login from '@/components/login/Login'


let LoginInstance = Vue.extend({
  components: { Login },
  template: `
    <login :login-visible.sync="loginVisible"
            @im-registe="ImRegiste"
            @login-success="loginSuccess"
            @forgetps="forgetps"
            @closed="closed"
    ></login>
  `,
  data () {
    return {
      loginVisible: false,
      resolve: () => {},
      reject: () => {},
    }
  },
  methods: {
    openLogin () {
      console.log('打开登录窗口');
      this.loginVisible = true
      return new Promise((resolve, reject) => {
        this.resolve = resolve
        this.reject = reject
      })
    },
    closeLogin () {
      console.log('关闭登录窗口');
      this.loginVisible = false
    },
    ImRegiste () {
      console.log('去注册了')
      this.resolve('regist')
      this.loginVisible = false
    },
    loginSuccess () {
      this.resolve('loginSuccess')
      console.log('登录成功');
      this.loginVisible = false
    },
    forgetps () {
      this.resolve('forgetps')
      console.log('忘记密码')
      this.$router.push({name: 'ForgetPassword'})
      this.loginVisible = false
    },
    closed () {
      this.resolve('closed')
      console.log('不登录了');
    }
  },
  watch: {
    'loginVisible' (val) {
      console.log('3333333333333', val);
    }
  }
})

const div = document.createElement('div')
div.setAttribute('id', 'mount-login')
document.body.appendChild(div)

const vmLogin = new LoginInstance({
  el: '#mount-login',
  router,
  store
})
Vue.prototype.$testopenLogin = vmLogin.openLogin
Vue.prototype.$testcloseLogin = vmLogin.closeLogin
